let axios = require('axios')
var mapsUtil = require('./maps.js')

class JueJin {

    constructor(arg) {
        this.zhao_web = 'https://m.zhaoyj.work/first/#/'
        this.juejinApi = {
            baseUrl: 'https://api.juejin.cn',
            dataList: [
                {
                    label: "跃跃2020",
                    params: {
                        aid: "2608",
                        uuid: "7404771823463089675",
                        spider: "0",
                        msToken: "LZRYHY4n1uZNl3uWvrb_3E08eMQVfEiNOuNOKluHEFy2jdKb6Hxv5szRgSOmha5IsCKLll4o9AByVj3N8UuBO74ntiL3ink0qD0Gl_f2hGN4r_gSarLwf6pBudevnf4=",
                        a_bogus: "mysYkcg5Msm1D73Bz7Dz9c8EiDD0YWRzgZEPVmbXIUL5",
                    },
                    headers: {
                        'Content-Type': 'application/json',
                        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
                        'Cookie': 'csrf_session_id=3ac28ee1c1d827cd5b8d07d0b74bc616; _tea_utm_cache_2608=undefined; __tea_cookie_tokens_2608=%257B%2522web_id%2522%253A%25227404771823463089675%2522%252C%2522user_unique_id%2522%253A%25227404771823463089675%2522%252C%2522timestamp%2522%253A1724057812495%257D; passport_csrf_token=771d46174df91123afaf94d978dd5bb8; passport_csrf_token_default=771d46174df91123afaf94d978dd5bb8; n_mh=gsxc4bW8jRluV_mEWU1obfgEOJ4ySQSkumyEAXqk-uw; passport_auth_status=c85170f3ff6a70fb4172647c9083a465%2C; passport_auth_status_ss=c85170f3ff6a70fb4172647c9083a465%2C; sid_guard=76b80a40427e09a08e1760f7a14e041a%7C1724062692%7C31536000%7CTue%2C+19-Aug-2025+10%3A18%3A12+GMT; uid_tt=1d77bd1bdf3db411aa3c8fed016863fd; uid_tt_ss=1d77bd1bdf3db411aa3c8fed016863fd; sid_tt=76b80a40427e09a08e1760f7a14e041a; sessionid=76b80a40427e09a08e1760f7a14e041a; sessionid_ss=76b80a40427e09a08e1760f7a14e041a; is_staff_user=false; sid_ucp_v1=1.0.0-KGI4YTE0M2EyOWRkZThhZjhkMTlhZWZlY2E0MzUxOTc0YTZhYjk0MzkKFwinrLDA_fWxARDkt4y2BhiwFDgCQPEHGgJsZiIgNzZiODBhNDA0MjdlMDlhMDhlMTc2MGY3YTE0ZTA0MWE; ssid_ucp_v1=1.0.0-KGI4YTE0M2EyOWRkZThhZjhkMTlhZWZlY2E0MzUxOTc0YTZhYjk0MzkKFwinrLDA_fWxARDkt4y2BhiwFDgCQPEHGgJsZiIgNzZiODBhNDA0MjdlMDlhMDhlMTc2MGY3YTE0ZTA0MWE; store-region=cn-nm; store-region-src=uid'
                    }
                },
                {
                    label: "雪狼组",
                    params: {
                        aid: "2608",
                        uuid: "7405119648926369314",
                        spider: "0",
                        msToken: "hjhBNVOU6dPOvYd1RIdMsIonkFpEJN50elC-2pGrywB9XL9qAUfueLv847A81iubsO9qjt0Qp2QF-K5Rwd7ZK5NuFA-vPOJH7Xg22K1dpa3nQXYgHsUoOhzwqzCJttD7",
                        a_bogus: "E6MOXOZqMsm1-XvELXDz9tEE5080YW-/gZEPz5N2F0w/",
                    },
                    headers: {
                        'Content-Type': 'application/json',
                        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15',
                        'Cookie': 'csrf_session_id=56007ef2918ee716e2798211dde255b6; _tea_utm_cache_576092=undefined; _ga_S695FMNGPJ=GS1.2.1724424152.1.0.1724424152.60.0.0; store-region=cn-js; store-region-src=uid; _ga=GA1.2.92673453.1724424151; _gid=GA1.2.45568762.1724424151; is_staff_user=false; n_mh=lHog-yHPiDK-3LNYtgMtPS-eL0aVbg5_4b1bZDUxovA; sessionid=ac37c8f47d345ca8dde2980e6b509814; sessionid_ss=ac37c8f47d345ca8dde2980e6b509814; sid_guard=ac37c8f47d345ca8dde2980e6b509814%7C1724424150%7C31536000%7CSat%2C+23-Aug-2025+14%3A42%3A30+GMT; sid_tt=ac37c8f47d345ca8dde2980e6b509814; sid_ucp_v1=1.0.0-KDljNGM4NGM4ZjExMTAwYTI1MzA3MTIwNTgzOGRmZDU3ZDM0MDViY2YKFgjM2uCL-M24BRDWv6K2BhiwFDgIQAsaAmxmIiBhYzM3YzhmNDdkMzQ1Y2E4ZGRlMjk4MGU2YjUwOTgxNA; ssid_ucp_v1=1.0.0-KDljNGM4NGM4ZjExMTAwYTI1MzA3MTIwNTgzOGRmZDU3ZDM0MDViY2YKFgjM2uCL-M24BRDWv6K2BhiwFDgIQAsaAmxmIiBhYzM3YzhmNDdkMzQ1Y2E4ZGRlMjk4MGU2YjUwOTgxNA; uid_tt=11b09993778ace52170a4a723eeaa43d; uid_tt_ss=11b09993778ace52170a4a723eeaa43d; passport_csrf_token=6552d0a466aff50a9de4c7e2f4c69c6f; passport_csrf_token_default=6552d0a466aff50a9de4c7e2f4c69c6f; __tea_cookie_tokens_2608=%257B%2522web_id%2522%253A%25227405119648926369314%2522%252C%2522user_unique_id%2522%253A%25227405119648926369314%2522%252C%2522timestamp%2522%253A1724138798285%257D; _tea_utm_cache_2608=undefined'
                    }
                }
            ]
        }
        this.gladosAPi = {
            baseUrl: "https://glados.rocks",
            cookie: `__stripe_mid=0f79c1bc-3da0-4feb-985f-e37a4f87f0948eb78c; koa:sess=eyJ1c2VySWQiOjUxNjA5LCJfZXhwaXJlIjoxNzEyMTI3ODUxNTgxLCJfbWF4QWdlIjoyNTkyMDAwMDAwMH0=; koa:sess.sig=puuRd4H_lFrWptURJbIMVppb1Mg; _gid=GA1.2.2026348706.1690937726; Cookie=enabled; Cookie.sig=lbtpENsrE0x6riM8PFTvoh9nepc; _ga=GA1.1.1669776694.1681349288; _ga_CZFVKMNT9J=GS1.1.1690937721.29.1.1690938331.0.0.0`,
            Authorization: '2955106794105734180656862944519-1381-1565',
            token: 'glados.one'
        }
    }

    async visitWebSite() {
        const options = {method: 'GET', url: this.zhao_web,};
        let {data} = await axios(options)
        console.log("visitWebSite", data)
    }

    async getCheckStatusJueJin(reqData) {
        let {params, headers} = reqData
        let get_today_status_api = this.juejinApi.baseUrl + "/growth_api/v2/get_today_status"
        const options = {method: 'GET', url: get_today_status_api, params, headers};
        let {data} = await axios(options)
        console.log("getCheckStatusJueJin", data)
        return data
    }

    async checkInJueJin(reqData) {
        console.log("checkInJueJin")
        let {params, headers} = reqData
        let check_in_api = this.juejinApi.baseUrl + "/growth_api/v1/check_in"
        const options = {method: 'POST', url: check_in_api, params, data: {}, headers};
        console.log("checkInJueJin==options", options)
        let {data} = await axios(options)
        console.log("checkInJueJin==data", data)
        return data
    }

    async checkInProcessJueJin() {
        let jueJinCheckInList = [];
        for (const info of this.juejinApi.dataList) {
            let result, statusRes = await this.getCheckStatusJueJin(info)
            console.log("checkInResult", statusRes, statusRes.data.check_in_done)
            if (statusRes.data.check_in_done) result = {err_no: 0, err_msg: "已签到"}
            else result = await this.checkInJueJin(info)
            result = {label: info.label, ...result}
            console.log("result=====", result)
            jueJinCheckInList.push(result)
        }
        return jueJinCheckInList
    }

    async checkInProcessGlados() {
        let check_in_api = this.gladosAPi.baseUrl + "/api/user/checkin"
        let {cookie, Authorization, token} = this.gladosAPi
        const options = {
            method: 'POST',
            json: true,
            url: check_in_api,
            body: {token},
            headers: {cookie, Authorization}
        };
        let {data} = await axios(options)
        console.log("checkInProcessGlados", data)
        return data
    }

    async checkIn() {
        let result = {msg: '开始执行程序前111！'}
        result.jueJinCheckInList = await this.checkInProcessJueJin()
        result.gladosCheckIn = await this.checkInProcessGlados()
        result.mapCheckPhone = await mapsUtil.checkMapPhone()
        return result
    }
}

module.exports = new JueJin()
